package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.Duty;
import com.ruoyi.service.IDutyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * dutyController
 * 
 * @author ya
 * @date 2025-08-17
 */
@RestController
@RequestMapping("/duty/duty")
public class DutyController extends BaseController
{
    @Autowired
    private IDutyService dutyService;

    /**
     * 查询duty列表
     */
//    @PreAuthorize("@ss.hasPermi('duty:duty:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Duty duty)
    {
        startPage();
        List<Duty> list = dutyService.selectDutyList(duty);
        return getDataTable(list);
    }

    /**
     * 导出duty列表
     */
    @PreAuthorize("@ss.hasPermi('duty:duty:export')")
    @Log(title = "duty", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Duty duty)
    {
        List<Duty> list = dutyService.selectDutyList(duty);
        ExcelUtil<Duty> util = new ExcelUtil<Duty>(Duty.class);
        util.exportExcel(response, list, "duty数据");
    }

    /**
     * 获取duty详细信息
     */
    @PreAuthorize("@ss.hasPermi('duty:duty:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dutyService.selectDutyById(id));
    }

    /**
     * 新增duty
     */
    @PreAuthorize("@ss.hasPermi('duty:duty:add')")
    @Log(title = "duty", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Duty duty)
    {
        return toAjax(dutyService.insertDuty(duty));
    }

    /**
     * 修改duty
     */
    @PreAuthorize("@ss.hasPermi('duty:duty:edit')")
    @Log(title = "duty", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Duty duty)
    {
        return toAjax(dutyService.updateDuty(duty));
    }

    /**
     * 删除duty
     */
    @PreAuthorize("@ss.hasPermi('duty:duty:remove')")
    @Log(title = "duty", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dutyService.deleteDutyByIds(ids));
    }
}
